<?php

/**
 * @author yuxun
 * 趣炫数据中心接入
 */
class DataCenterController extends Controller {
	public function __construct($id,$module=null){
		parent::__construct();
	}

	
	public function beforeAction($action){
		$local_sign = $this->getSign();
		
		$sign = PubRequest::R('sign');

		if($local_sign != $sign){
			$json_arr = array('state'=>1,'msg'=>'check_sign_err' );
			ApiBaseService::doLog($_POST, $json_arr);
			exit(json_encode($json_arr));
		}
			
		return parent::beforeAction($action);
	}
	
	
	/**
	 * md5(key1=value1&key2=value2&key3=value3+api_key) ; 
其中“+”号只做连接作用实际上并没参与加密，各参数之间没有空格，按参数字段升序排列后，以键值对形式拼接.
（备注：sign签名需要md5加密而成）
	 * @return string
	 */
	protected function getSign(){
		header("Content-type:text/html;charset=utf-8");
		$key = Yii::app()->params['API_SECRET_KEY'];
		$data = $_POST;

		unset($data['sign']);   
		ksort($data);
		$sign = md5($key.http_build_query($data));
		
		return $sign;
	}
    
	/**
	 * 获取专服列表
	 * http://admin.s10.q-dazzle.com:8090/api/?r=dataCenter/getPlatList
	 */
	public function getPlatList(){        
		$json_arr = DataCenterService::getPlatList();
		ApiBaseService::doLog($_POST, $json_arr);
		exit(json_encode($json_arr));
	}
	
	/**
	 * 获取服务器列表
	 * http://admin.s10.q-dazzle.com:8090/api/?r=dataCenter/getServerList
	 */
	public function getServerList(){
		$json_arr = DataCenterService::getServerList();
		ApiBaseService::doLog($_POST, $json_arr);
		exit(json_encode($json_arr));
	}
	
	/**
	 * 获取内玩账号信息
	 * http://admin.s10.q-dazzle.com:8090/api/?r=dataCenter/getInsideList
	 */
	public function getInsideList(){
		$json_arr = DataCenterService::getInsideList();
		ApiBaseService::doLog($_POST, $json_arr);
		exit(json_encode($json_arr)); 
	}
	
	/**
	 * 获取游戏服登陆人数
	 * http://admin.s10.q-dazzle.com:8090/api/?r=dataCenter/getLoginNum
	 */
	public function getLoginNum(){
		$plat_id = PubRequest::R('plat_id');
		$server_id = PubRequest::R('server_id');
		$date = PubRequest::R('date');
		$time = PubRequest::R('time');
		
		$json_arr = DataCenterService::getLoginNum($plat_id,$server_id,$date,$time);
		ApiBaseService::doLog($_POST, $json_arr);
		exit(json_encode($json_arr));
	}
	
	
   

}